<%--
  Created by IntelliJ IDEA.
  User: ZYJY
  Date: 2020-08-11
  Time: 15:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <base href="${pageContext.request.contextPath}/">
    <script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
    <script>
        function getEmp() {
            $.ajax({
                type: "get",
                url: "emp/getEmp/234/张三",
                dataType:"json",
                success: function(data){
                    console.log(data);
                }
            });
        }
        
        function selectAll() {
            $.ajax({
                type: "get",
                url: "emp/selectAll",
                dataType:"json",
                success: function(data){
                    for(var i = 0; i < data.length; i++){
                        console.log(data[i]);
                    }
                }
            });
        }
        
        function insertEmp() {
            var emp = {
               empno:100,
               ename:"张三",
               sal:2345.6,
                job:"研发",
                 hiredate:"2018-08-08",
                dept:{
                    dempno:12345,
                    dname:"研发"
                },
                hobbies: ["吃","喝"]
            };
            $.ajax({
                type: "post",
                url: "emp/insertEmp",
                dataType:"json",
                data:JSON.stringify(emp),
                contentType:"application/json",
                success: function(result){
                    console.log(result);
                }
            });
        }
        
        function deleteEmp() {
            $.ajax({
                type: "delete",
                url: "emp/deleteEmp/111",
                dataType:"json",
                success: function(result){
                   console.log(result);
                }
            });
        }
        
        function updateEmp() {
            var emp = {
                empno:100,
                ename:"张三",
                sal:2345.6,
                job:"研发",
                hiredate:"2018-08-08",
                "dept.dempno":234,
                "dept.dname":"研发部",
                hobbies:["吃","喝"]
            };
            $.ajax({
                type: "put",
                url: "emp/updateEmp",
                dataType:"json",
                data:JSON.stringify(emp),
                contentType:"application/json",
                success: function(result){
                    console.log(result);
                }
            });
        }
    </script>
    <title>Title</title>

</head>
<body>
<h1>index</h1>
<button onclick="getEmp()">get请求</button>
<button onclick="selectAll()">selectAll-->get</button>
<button onclick="insertEmp()">addEmp</button>
<button onclick="deleteEmp()">deleteEmp</button>
<button onclick="updateEmp()">updateEmp</button>
<hr>
<div>
    <form action="emp/deleteEmp/123" method="post">
        <input type="hidden" name="_method" value="delete"/>
        <input type="submit" value="提交"/>
    </form>
</div>

<hr/>

<div>
    <form action="emp/updateEmp" method="post">
        <input type="hidden" name="_method" value="put"/>
        <input type="text" name="empno"/><br/>
        <input type="text" name="ename"/>
        <input type="submit" value="提交"/>
    </form>
</div>
</body>
</html>